<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="月份" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="month">
              <a-input v-model="model.month" placeholder="请输入月份" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="username">
              <a-input v-model="model.username" placeholder="请输入账号" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="realname">
              <a-input v-model="model.realname" placeholder="请输入姓名" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="职位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="post">
              <a-input v-model="model.post" placeholder="请输入职位" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="级别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="level">
              <a-input v-model="model.level" placeholder="请输入级别" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="departName">
              <a-input v-model="model.departName" placeholder="请输入所属部门" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机构编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgCode">
              <a-input v-model="model.orgCode" placeholder="请输入机构编码" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="城市" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cityName">
              <a-input v-model="model.cityName" placeholder="请输入城市" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="城市code" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cityCode">
              <a-input v-model="model.cityCode" placeholder="请输入城市code" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="城市级别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cityLevel">
              <a-input v-model="model.cityLevel" placeholder="请输入城市级别" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="团队名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamName">
              <a-input v-model="model.teamName" placeholder="请输入团队名称" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="薪资" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="salary">
              <a-input-number v-model="model.salary" placeholder="请输入薪资" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="线索人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leads">
              <a-input-number v-model="model.leads" placeholder="请输入线索人数" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="入职人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="entry">
              <a-input-number v-model="model.entry" placeholder="请输入入职人数" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="确权人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="confirm">
              <a-input-number v-model="model.confirm" placeholder="请输入确权人数" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="营销账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="marketAccount">
              <a-input v-model="model.marketAccount" placeholder="请输入营销账号" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="营销费用(系统核算)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="market">
              <a-input-number v-model="model.market" placeholder="请输入营销费用(系统核算)" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="营销费用(人工上报)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="marketManual">
              <a-input-number v-model="model.marketManual" placeholder="请输入营销费用(人工上报)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="办公场地(均摊)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="officeSpace">
              <a-input-number v-model="model.officeSpace" placeholder="请输入办公场地(均摊)" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="办公家具(均摊)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="officeFurniture">
              <a-input-number v-model="model.officeFurniture" placeholder="请输入办公家具(均摊)" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="其他" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="other">
              <a-input-number v-model="model.other" placeholder="请输入其他" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总支出" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalPay">
              <a-input-number v-model="model.totalPay" placeholder="请输入总支出" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总收入" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalIncome">
              <a-input-number v-model="model.totalIncome" placeholder="请输入总收入" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注" disabled ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'EmpIncomeForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/emp/empIncome/add",
          edit: "/emp/empIncome/edit",
          queryById: "/emp/empIncome/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>